| Conditions | 1 |
| Paths | 2 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 53 | function sendRequest(form) |
||
| 54 | { |
||
| 55 | $('#toggle-lang-response').trigger('click'); |
||
| 56 | |||
| 57 | var $form = $(form); |
||
| 58 | var $section = $form.closest('section'); |
||
| 59 | |||
| 60 | var $btn = $form.find('button[type="submit"]'); |
||
| 61 | $btn.html($('#preloader-template').html()).attr('disabled', true); |
||
| 62 | |||
| 63 | var headers = {}; |
||
| 64 | $section.find('.headers-form .form-group').not('.except').each(function(key, element) { |
||
| 65 | var $el = $(element); |
||
| 66 | if ($el.find('.req-header-active').is(':checked')) { |
||
| 67 | var header = $el.find('.req-header').val(); |
||
| 68 | headers[header] = $el.find('.req-header-value').val(); |
||
| 69 | } |
||
| 70 | }); |
||
| 71 | |||
| 72 | $.ajax({ |
||
| 73 | url : $section.find('.action-url').val(), |
||
| 74 | headers: headers, |
||
| 75 | type : $form.attr('method'), |
||
| 76 | data : $form.serializeArray(), |
||
| 77 | success : function(response, status, xhr) { |
||
| 78 | $btn.text('Send').attr('disabled', false); |
||
| 79 | $section.find('.method-example-endpoint code.response-content').jsonViewer(response); |
||
| 80 | $section.find('.method-example-endpoint code.response-headers').text(xhr.getAllResponseHeaders()); |
||
| 81 | }, |
||
| 82 | error : function(xhr) { |
||
| 83 | $btn.text('Send').attr('disabled', false); |
||
| 84 | var content = xhr.responseText; |
||
| 85 | if (xhr.statusText && !content) { |
||
| 86 | $.notify({ |
||
| 87 | message: xhr.statusText |
||
| 88 | },{ |
||
| 89 | type: 'danger' |
||
| 90 | }); |
||
| 91 | } |
||
| 92 | if (IsJsonString(content)) { |
||
| 93 | $section.find('.method-example-endpoint code.response-content').jsonViewer(content); |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | var $frame = $('<iframe class="supa" style="width:100%; height:350px;">'); |
||
| 97 | $section.find('.method-example-endpoint code.response-content').html($frame); |
||
| 98 | setTimeout(function() { |
||
| 99 | var doc = $frame[0].contentWindow.document; |
||
| 100 | var $body = $('body', doc); |
||
| 101 | $body.html(content); |
||
| 102 | }, 1); |
||
| 103 | |||
| 104 | $section.find('.method-example-endpoint code.response-headers').text(xhr.getAllResponseHeaders()); |
||
| 105 | } |
||
| 106 | }); |
||
| 107 | |||
| 108 | return false; |
||
| 109 | } |
||
| 110 | |||
| 145 |